/**
 * 制作者：九哥
 * 消息数据对接
 * 时间：2019-05-21
 * */

/**
 * 引入缓存设置文件 cache.js
 * */
document.write("<script type='text/javascript' src='/h5/js/cache.js'></script>");


//var app_access = 'qSoiKwpWVge4TkaryH6MKvOdceGt7ZMaF20g8H0cnXI';

/**
 * 新消息提醒
 * */
function getNewTips(){
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        getErrMsg('没有登录！',''); return;
    }
    var data = {
        app_access:app_access,
        token:userInfo.token,
        type:userInfo.type,
        cate:userInfo.cate
    };
    $.ajax({
        type:'post',
        url:getDomain() + 'index',
        data:data,
        success:function(res){
            if (res.code!=0) {
                console.log(res); return;
            }
            $('#business').html(res.data.business);
            $('#job').html(res.data.job);
            $('#sys').html(res.data.sys);
            $('#inside').html(res.data.inside);
            $('#reward').html(res.data.reward);
        },
        error:function(){
            console.log('操作失败！'); return;
        }
    });
}

/**
 * 商务消息列表
 * */
function getCompanys(){
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        getErrMsg('没有登录！',''); return;
    }
    var data = {
        app_access:app_access,
        token:userInfo.token,
        type:userInfo.type,
        cate:userInfo.cate
    };
    $.ajax({
        type:'post',
        url:getDomain() + 'company',
        data:data,
        success:function(res){
            //console.log(res); return;
            var h = '';
            if (res.code!=0) {
                //h += '<a href="javascript:;" class="aui-six-list-item">';
                //h +=    '<div class="aui-flex b-line">';
                //h +=        '<div class="aui-flex-box">';
                //h +=            '<h3>Alibaba来信</h3>';
                //h +=            '<p>新消息</p>';
                //h +=        '</div>';
                //h +=    '</div>';
                //h += '</a>';
                h += '<div style="padding:10px;text-align:center;">没有会话</div>';
                $('#msglist').html(h);
                console.log(res); return;
            }
            //console.log(res.data); return;
            var i, data = res.data; h = '';
            for (i=0;i<data.length;i++) {
                h += '<a href="comWin.html?id='+data[i].id+'&comName='+data[i].comName+'" class="aui-six-list-item">';
                h +=    '<div class="aui-flex b-line">';
                h +=        '<div class="aui-flex-box">';
                h +=            '<h3>消息来自：'+data[i].comName+'</h3>';
                h +=            '<p>新消息';
                h +=            data[i].new+'&nbsp; &nbsp;'+data[i].lastTime;
                h +=            '</p>';
                h +=        '</div>';
                h +=        '<div class="aui-flex-box" style="position:absolute;right:20px">';
                h +=            '<p>去交流</p>';
                h +=        '</div>';
                h +=    '</div>';
                h += '</a>';
            }
            $('#msglist').html(h);
            //保存到缓存
            var talkCacheKey = 'msgCompany';
            var talkArr = new Array();
            for (i=0;i<data.length;i++) {
                talkArr[i] = {
                    id:data[i].id,
                    comName:data[i].comName,
                    new:data[i].new,
                    lastTime:data[i].lastTime
                };
            }
            cacheSet(talkCacheKey,talkArr);
            console.log('获取消息，更新缓存成功！');
        },
        error:function(){
            console.log('操作失败！'); return;
        }
    });
}

/**
 * 商务消息列表
 * 获取本地列表缓存
 * */
function getCompanyCache(){
    var talkCacheKey = 'msgCompany';
    var talkCache = cacheGet(talkCacheKey);
    if (talkCache==null || talkCache=='undefined' || talkCache=='') {
        console.log('没有缓存！'); return;
    }
    var i, h = '', data = talkCache;
    for (i=0;i<data.length;i++) {
        h += '<a href="comWin.html?id='+data[i].id+'&comName='+data[i].comName+'" class="aui-six-list-item">';
        h +=    '<div class="aui-flex b-line">';
        h +=        '<div class="aui-flex-box">';
        h +=            '<h3>消息来自：'+data[i].comName+'</h3>';
        h +=            '<p>新消息';
        h +=            data[i].new+'&nbsp; &nbsp;'+data[i].lastTime;
        h +=            '</p>';
        h +=        '</div>';
        h +=        '<div class="aui-flex-box" style="position:absolute;right:20px">';
        h +=            '<p>去交流</p>';
        h +=        '</div>';
        h +=    '</div>';
        h += '</a>';
    }
    $('#msglist').html(h);
}

/**
 * 商务会话，接收消息
 * */
function getComAccept(){
    var talkId = $('#talkId').val();
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        getErrMsg('没有登录！',''); return;
    }
    var data = {
        app_access:app_access,
        token:userInfo.token,
        type:userInfo.type,
        cate:userInfo.cate,
        talkId:talkId
    };
    $.ajax({
        type:'post',
        url:getDomain() + 'accept',
        data:data,
        success:function(res){
            //console.log(res); return;
            if (res.code!=0) {
                getAppErrMsg('没有最新消息！','',1000);
                console.log(res.msg); return;
            }
            var i, data = res.data, answer = '';
            for (i=0;i<data.length;i++) {
                answer += '<div class="answer" id="answer_'+data[i].id+'">';
                answer += '<div class="heard_img left">';
                answer += '<img src="../images/toux01.png" height="40">';
                answer += '</div>';
                answer += '<div class="answer_text">';
                answer += '<p>'+data[i].detail+'</p>';
                answer += '<i></i>';
                answer += '</div>';
                answer += '</div>';
            }
            $('.speak_box').append(answer);
            $('.write_box input').val('');
            $('.write_box input').focus();
            //更新对话框到底部
            //document.getElementById("answer_"+data[i].id).scrollIntoView();
            $('#answer_'+data[i].id).scrollIntoView();
            //保存到缓存
            var talkCacheKey = 'msgComWin_'+talkId;
            var i2, i3;
            var talkCache = cacheGet(talkCacheKey);
            var talkArr = new Array();
            if (talkCache=='' || talkCache==null || talkCache=='undefined') {
                console.log('没有历史缓存！');
                for (i2=0;i2<data.length;i2++) {
                    talkArr[i2] = {
                        align:'left',
                        head:'../images/toux01.png',
                        detail:data[i2].detail
                    };
                }
                cacheSet(talkCacheKey,talkArr);
            } else {
                talkArr = talkCache;
                for (i3=0;i3<data.length;i3++) {
                    talkArr[data.length] = {
                        align:'left',
                        head:'../images/toux01.png',
                        detail:data[i3].detail
                    };
                }
                cacheSet(talkCacheKey,talkArr);
            }
            console.log('获取消息，更新缓存成功！');
        },
        error:function(){
            console.log('操作失败！'); return;
        }
    });
}

/**
 * 商务会话，发送消息
 * */
function setComSend(){
    var quest = $('#quest').val();
    var talkId = $('#talkId').val();
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        getAppErrMsg('没有登录！','',1000); return;
    }
    if (quest==null || quest=='' || quest=='undefined') {
        getAppErrMsg('没有输入消息！','',1000); return;
    }
    var data = {
        app_access:app_access,
        token:userInfo.token,
        type:userInfo.type,
        cate:userInfo.cate,
        talkId:talkId,
        quest:quest
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'send',
        data: data,
        success: function(res){
            //console.log(res); return
            if (res.code!=0) {
                console.log(res.msg); return;
            }
            var data = res.data;
            //更新到对话框
            var question = '';
            question += '<div class="question" id="quest_'+data.id+'">';
            question += '<div class="heard_img right">';
            question += '<img src="../images/toux01.png" height="40">';
            question += '</div>';
            question += '<div class="question_text">';
            question += '<p>测试测试</p>';
            question += '<i></i>';
            question += '</div>';
            question += '</div>';
            $('.speak_box').append(question);
            $('.write_box input').val('');
            $('.write_box input').focus();
            //更新对话框到底部
            //document.getElementById("quest_"+data.id).scrollIntoView();
            if($('#quest_'+data.id)[0]){
                $('#quest_'+data.id).scrollIntoView();
            }

            //保存消息到缓存
            var talkCacheKey = 'msgComWin_'+talkId;
            var talkCache = cacheGet(talkCacheKey);
            var talkArr = new Array();
            if (talkCache=='' || talkCache==null || talkCache=='undefined') {
                console.log('没有历史缓存！');
                talkArr[0] = {
                    align:'right',
                    head:'../images/toux01.png',
                    detail:quest
                };
                cacheSet(talkCacheKey,talkArr);
            } else {
                talkArr = talkCache;
                talkArr[talkCache.length] = {
                    align:'right',
                    head:'../images/toux01.png',
                    detail:quest
                };
                cacheSet(talkCacheKey,talkArr);
            }
            console.log('发送消息，更新缓存成功！');
            //获取消息
            setTimeout(function(){
                getComAccept();
            },1000*2);
        },
        error:function(){
            console.log('操作失败！'); return;
        }
    });
}

/**
 * 招聘消息列表
 * */
function getJobTalks(){
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        getErrMsg('没有登录！',''); return;
    }
    var data = {
        app_access:app_access,
        token:userInfo.token,
        type:userInfo.type,
        cate:userInfo.cate
    };
    $.ajax({
        type:'post',
        url:getDomain() + 'job',
        data:data,
        success:function(res){
            //console.log(res); return;
            var h = '';
            if (res.code!=0) {
                //h += '<a href="javascript:;" class="aui-six-list-item">';
                //h +=    '<div class="aui-flex b-line">';
                //h +=        '<div class="aui-flex-box">';
                //h +=            '<h3>Alibaba来信</h3>';
                //h +=            '<p>新消息</p>';
                //h +=        '</div>';
                //h +=    '</div>';
                //h += '</a>';
                h += '<div style="padding:10px;text-align:center;">没有会话</div>';
                $('#msglist').html(h);
                console.log(res); return;
            }
            //console.log(res.data); return;
            var data = res.data;
            for (var i=0;i<data.length;i++) {
                var prefix = '?id='+data[i].id+'&own='+data[i].own+'&other='+data[i].other+'&otherName='+data[i].otherName+'&jobId='+data[i].jobId;
                h += '<a href="jobWin.html'+prefix+'" class="aui-six-list-item">';
                //h += '<a href="jobWin.html?id='+data[i].id+'&otherName='+data[i].otherName+'" class="aui-six-list-item">';
                h +=    '<div class="aui-flex b-line">';
                h +=        '<div class="aui-flex-box">';
                h +=            '<h3>来自：';
                if (data[i].otherName.length < 6) {
                    h += data[i].otherName;
                } else {
                    h += data[i].otherName.substring(0,6) + '...';
                }
                h +=            '</h3>';
                //h +=            '<p>新消息';
                //h +=            data[i].new+'&nbsp; &nbsp;'+data[i].lastTime;
                h +=            '<p>'+data[i].lastTime;
                h +=            '</p>';
                h +=        '</div>';
                h +=        '<div class="aui-flex-box" style="position:absolute;right:20px">';
                h +=            '<p>去交流</p>';
                h +=        '</div>';
                h +=    '</div>';
                h += '</a>';
            }
            $('#msglist').html(h);
            ////保存到缓存
            //var talkCacheKey = 'msgJob';
            //var talkArr = new Array();
            //for (i=0;i<data.length;i++) {
            //    talkArr[i] = {
            //        id:data[i].id,
            //        otherName:data[i].otherName,
            //        new:data[i].new,
            //        lastTime:data[i].lastTime
            //    };
            //}
            //cacheSet(talkCacheKey,talkArr);
            //console.log('获取消息，更新缓存成功！');
        },
        error:function(){
            console.log('操作失败！'); return;
        }
    });
}

/**
 * 招聘消息列表
 * 获取本地列表缓存
 * */
function getJobCache(){
    var talkCacheKey = 'msgJob';
    var talkCache = cacheGet(talkCacheKey);
    if (talkCache==null || talkCache=='undefined' || talkCache=='') {
        console.log('没有缓存！'); return;
    }
    var i, h = '', data = talkCache;
    for (i=0;i<data.length;i++) {
        h += '<a href="jobWin.html?id='+data[i].id+'&otherName='+data[i].otherName+'" class="aui-six-list-item">';
        h +=    '<div class="aui-flex b-line">';
        h +=        '<div class="aui-flex-box">';
        h +=            '<h3>消息来自：'+data[i].otherName+'</h3>';
        h +=            '<p>新消息';
        h +=            data[i].new+'&nbsp; &nbsp;'+data[i].lastTime;
        h +=            '</p>';
        h +=        '</div>';
        h +=        '<div class="aui-flex-box" style="position:absolute;right:20px">';
        h +=            '<p>去交流</p>';
        h +=        '</div>';
        h +=    '</div>';
        h += '</a>';
    }
    $('#msglist').html(h);
}

/**
 * 招聘会话，接收消息
 * */
function getJobAccept(){
    var talkId = $('#talkId').val();
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        getErrMsg('没有登录！',''); return;
    }
    var data = {
        app_access:app_access,
        token:userInfo.token,
        type:userInfo.type,
        cate:userInfo.cate,
        talkId:talkId
    };
    $.ajax({
        type:'post',
        url:getDomain() + 'accept',
        data:data,
        success:function(res){
            //console.log(res); return;
            if (res.code!=0) {
                getAppErrMsg('没有最新消息！','',1000);
                console.log(res.msg); return;
            }
            var i, data = res.data, answer = '';
            for (i=0;i<data.length;i++) {
                answer += '<div class="answer" id="answer_'+data[i].id+'">';
                answer += '<div class="heard_img left">';
                answer += '<img src="../images/toux01.png" height="40">';
                answer += '</div>';
                answer += '<div class="answer_text">';
                answer += '<p>'+data[i].detail+'</p>';
                answer += '<i></i>';
                answer += '</div>';
                answer += '</div>';
            }
            $('.speak_box').append(answer);
            $('.write_box input').val('');
            $('.write_box input').focus();
            //更新对话框到底部
            //document.getElementById("answer_"+data[i].id).scrollIntoView();
            if(data[i]&&$('#answer_'+data[i].id)[0]){
                $('#answer_'+data[i].id).scrollIntoView();
            }

            ////保存到缓存
            //var talkCacheKey = 'msgJobWin_'+talkId;
            //var i2, i3;
            //var talkCache = cacheGet(talkCacheKey);
            //var talkArr = new Array();
            //if (talkCache=='' || talkCache==null || talkCache=='undefined') {
            //    console.log('没有历史缓存！');
            //    for (i2=0;i2<data.length;i2++) {
            //        talkArr[i2] = {
            //            align:'left',
            //            head:'../images/toux01.png',
            //            detail:data[i].detail
            //        };
            //    }
            //    cacheSet(talkCacheKey,talkArr);
            //} else {
            //    talkArr = talkCache;
            //    for (i3=0;i3<data.length;i3++) {
            //        var index = (talkCache.length-1)*1+i3;
            //        talkArr[index] = {
            //            align:'left',
            //            head:'../images/toux01.png',
            //            detail:data[i].detail
            //        };
            //    }
            //    cacheSet(talkCacheKey,talkArr);
            //}
            //console.log('获取消息，更新缓存成功！');
        },
        error:function(){
            console.log('操作失败！'); return;
        }
    });
}

/**
 * 招聘会话，发送消息
 * */
function setJobSend(){
    var quest = $('#quest').val();
    var talkId = $('#talkId').val();
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        getErrMsg('没有登录！',''); return;
    }
    if (quest==null || quest=='' || quest=='undefined') {
        getErrMsg('没有输入消息！',''); return;
    }
    var data = {
        app_access:app_access,
        token:userInfo.token,
        type:userInfo.type,
        cate:userInfo.cate,
        talkId:talkId,
        quest:quest
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'send',
        data: data,
        success: function(res){
            //console.log(res); return
            if (res.code!=0) {
                console.log(res.msg); return;
            }
            //更新到对话框
            var data = res.data;
            var question = '';
            question += '<div class="question" id="quest_'+data.id+'">';
            question += '<div class="heard_img right">';
            question += '<img src="../images/toux01.png" height="40">';
            question += '</div>';
            question += '<div class="question_text">';
            question += '<p>'+quest+'</p>';
            question += '<i></i>';
            question += '</div>';
            question += '</div>';
            $('.speak_box').append(question);
            $('.write_box input').val('');
            $('.write_box input').focus();
            //更新对话框到底部
            //document.getElementById("quest_"+data.id).scrollIntoView();
            if($('#quest_'+data.id)[0]&&$('#quest_'+data.id).scrollIntoView){
                $('#quest_'+data.id).scrollIntoView();
            }

            //保存消息到缓存
            var talkCacheKey = 'msgJobWin_'+talkId;
            var talkCache = cacheGet(talkCacheKey);
            var talkArr = new Array();
            if (talkCache=='' || talkCache==null || talkCache=='undefined') {
                console.log('没有历史缓存！');
                talkArr[0] = {
                    align:'right',
                    head:'../images/toux01.png',
                    detail:quest
                };
                cacheSet(talkCacheKey,talkArr);
            } else {
                talkArr = talkCache;
                talkArr[talkCache.length] = {
                    align:'right',
                    head:'../images/toux01.png',
                    detail:quest
                };
                cacheSet(talkCacheKey,talkArr);
            }
            console.log('发送消息，更新缓存成功！');
            //获取消息
            setTimeout(function(){
                getJobAccept();
            },1000*2);
        },
        error:function(){
            console.log('操作失败！'); return;
        }
    });
}

/**
 * 系统消息
 * */
function getSystems(){
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        getErrMsg('没有登录！',''); return;
    }
    var data = {
        app_access:app_access,
        token:userInfo.token,
        type:userInfo.type,
        cate:userInfo.cate
    };
    $.ajax({
        type:'post',
        url:getDomain() + 'sys',
        data:data,
        success:function(res){
            //console.log(res); return;
            var h = '';
            if (res.code!=0) {
                //h += '<a href="javascript:;" class="aui-six-list-item">';
                //h +=    '<div class="aui-flex b-line">';
                //h +=        '<div class="aui-flex-box">';
                //h +=            '<h3>系统信息</h3>';
                //h +=            '<p>新消息</p>';
                //h +=        '</div>';
                //h +=    '</div>';
                //h += '</a>';
                h += '<div style="padding:10px;text-align:center;">没有消息</div>';
                $('#msglist').html(h);
                console.log(res); return;
            }
            //console.log(res.data); return;
            var i, data = res.data; h = '';
            var isread='';
            for (i=0;i<data.length;i++) {
                if(SysMsg.isdu(data[i].id)){
                    isread='read';
                }else{
                    isread='noread';
                }
                h += '<a href="sysShow.html?id='+data[i].id+'" class="aui-six-list-item '+isread+' ">';
                h +=    '<div class="aui-flex b-line">';
                h +=        '<div class="aui-flex-box">';
                h +=            '<h3>'+data[i].title+'</h3>';
                h +=            '<p>';
                if (data[i].statusName) { h += '新消息&nbsp; &nbsp;'; }
                h +=            data[i].createTime;
                h +=            '</p>';
                h +=        '</div>';
                h +=        '<div class="aui-flex-box" style="position:absolute;right:20px">';
                h +=            '<p>看详情</p>';
                h +=        '</div>';
                h +=    '</div>';
                h += '</a>';
            }
            $('#msglist').html(h);
            //保存到缓存
            var talkCacheKey = 'msgSystem';
            var talkArr = new Array();
            for (i=0;i<data.length;i++) {
                talkArr[i] = {
                    id:data[i].id,
                    title:data[i].title,
                    statusName:data[i].statusName,
                    createTime:data[i].createTime,
                    detail:''
                };
            }
            cacheSet(talkCacheKey,talkArr);
            console.log('获取消息，更新缓存成功！');
        },
        error:function(){
            console.log('操作失败！'); return;
        }
    });
}

/**
 * 系统消息列表
 * 获取本地列表缓存
 * */
function getSysCache(){
    var talkCacheKey = 'msgSystem';
    var talkCache = cacheGet(talkCacheKey);
    if (talkCache==null || talkCache=='undefined' || talkCache=='') {
        console.log('没有缓存！'); return;
    }
    var i, h = '', data = talkCache;
    var isread='';
    for (i=0;i<data.length;i++) {
        if(SysMsg.isdu(data[i].id)){
            isread='read';
        }else{
            isread='noread';
        }
        h += '<a href="sysShow.html?id='+data[i].id+'" class="aui-six-list-item '+isread+'">';
        h +=    '<div class="aui-flex b-line">';
        h +=        '<div class="aui-flex-box">';
        h +=            '<h3>'+data[i].title+'</h3>';
        h +=            '<p>';
        if (data[i].statusName) { h += '新消息&nbsp; &nbsp;'; }
        h +=            data[i].createTime;
        h +=            '</p>';
        h +=        '</div>';
        h +=        '<div class="aui-flex-box" style="position:absolute;right:20px">';
        h +=            '<p>看详情</p>';
        h +=        '</div>';
        h +=    '</div>';
        h += '</a>';
    }
    $('#msglist').html(h);
}

/**
 * 系统消息详情
 * */
function getSysShow(){
    var sysId = $('#sysId').val();
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        getErrMsg('没有登录！',''); return;
    }
    var data = {
        app_access:app_access,
        token:userInfo.token,
        type:userInfo.type,
        cate:userInfo.cate,
        sysId:sysId
    };
    $.ajax({
        type:'post',
        url:getDomain() + 'sys/show',
        data:data,
        success:function(res){
            //console.log(res); return;
            var h = '';
            if (res.code!=0) {
                h += '<div class="aui-flex b-line">';
                h +=    '<div class="aui-flex-box">';
                h +=        '<h3 class="sysTitle">消息标题</h3>';
                h +=        '<p class="sysTitle">2019-01-01</p><hr>';
                h +=        '<div class="sysDetail">消息内容</div>';
                h +=    '</div>';
                h += '</div>';
                $('#msglist').html(h);
                console.log(res); return;
            }
            //console.log(res.data); return;
            var data = res.data; h = '';
            h += '<div class="aui-flex b-line">';
            h +=    '<div class="aui-flex-box">';
            h +=        '<h3 class="sysTitle">'+data.title+'</h3>';
            h +=        '<p class="sysTitle">'+data.createTime+'</p><hr>';
            h +=        '<div class="sysDetail">'+data.detail+'</div>';
            h +=    '</div>';
            h += '</div>';
            $('#msgShow').html(h);
            //保存到缓存
            var talkCacheKey = 'msgSysShow';
            var talkArr = new Array();
            talkArr[sysId] = {
                title:data.title,
                statusName:data.statusName,
                createTime:data.createTime,
                detail:data.detail
            };
            cacheSet(talkCacheKey,talkArr);
            console.log('获取消息，更新缓存成功！');
        },
        error:function(){
            console.log('操作失败！'); return;
        }
    });
}

/**
 * 系统消息详情
 * 获取本地缓存
 * */
function getSysShowCache(sysId){
    var talkCacheKey = 'msgSysShow';
    var talkCache = cacheGet(talkCacheKey);
    if (talkCache==null || talkCache=='undefined' || talkCache==[]) { return ''; }
    var data = talkCache;
    var h = '';
    if (data[sysId]) {
        h += '<div class="aui-flex b-line">';
        h +=    '<div class="aui-flex-box">';
        h +=        '<h3 class="sysTitle">'+data[sysId].title+'</h3>';
        h +=        '<p class="sysTitle">'+data[sysId].createTime+'</p><hr>';
        h +=        '<div class="sysDetail">'+data[sysId].detail+'</div>';
        h +=    '</div>';
        h += '</div>';
    }
    $('#msgShow').html(h);
}

/**
 * 内部消息
 * */
function getGroups(){
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        getErrMsg('没有登录！',''); return;
    }
    var data = {
        app_access:app_access,
        token:userInfo.token,
        type:userInfo.type,
        cate:userInfo.cate
    };
    $.ajax({
        type:'post',
        url:getDomain() + 'group',
        data:data,
        success:function(res){
            //console.log(res); return;
            var h = '';
            if (res.code!=0) {
                //h += '<a href="groupStaff.html" class="aui-six-list-item">';
                //h +=    '<div class="aui-flex b-line">';
                //h +=        '<div class="aui-flex-box">';
                //h +=            '<h3>内部信息</h3>';
                //h +=            '<p>测试消息</p>';
                //h +=        '</div>';
                //h +=    '</div>';
                //h += '</a>';
                h += '<div style="padding:10px;text-align:center;">没有会话</div>';
                $('#msglist').html(h);
                console.log(res); return;
            }
            //console.log(res.data); return;
            var i, data = res.data; h = '';
            for (i=0;i<data.length;i++) {
                h += '<a href="groupWin.html?id='+data[i].id+'&groupName='+data[i].name+'" class="aui-six-list-item">';
                h +=    '<div class="aui-flex b-line">';
                h +=        '<div class="aui-flex-box">';
                h +=            '<h3>群名：'+data[i].name+'</h3>';
                h +=            '<p>';
                h +=            data[i].lastTime;
                h +=            '</p>';
                h +=        '</div>';
                h +=        '<div class="aui-flex-box" style="position:absolute;right:20px">';
                h +=            '<p>去交流</p>';
                h +=        '</div>';
                h +=    '</div>';
                h += '</a>';
            }
            $('#msglist').html(h);
            //保存到缓存
            var talkCacheKey = 'msgGroup';
            var talkArr = new Array();
            for (var i2=0;i2<data.length;i2++) {
                talkArr[i2] = {
                    id:data[i2].id,
                    name:data[i2].name,
                    lastTime:data[i2].lastTime
                };
            }
            cacheSet(talkCacheKey,talkArr);
            console.log('获取消息，更新缓存成功！');
        },
        error:function(){
            console.log('操作失败！'); return;
        }
    });
}

/**
 * 内部消息列表
 * 获取本地缓存
 * */
function getGroupCache(){
    var talkCacheKey = 'msgGroup';
    var talkCache = cacheGet(talkCacheKey);
    if (talkCache==null || talkCache=='undefined' || talkCache=='') {
        console.log('没有缓存！'); return;
    }
    var data = talkCache;
    var i, h = '';
    for (i=0;i<data.length;i++) {
        h += '<a href="groupWin.html?id='+data[i].id+'&groupName='+data[i].name+'" class="aui-six-list-item">';
        h +=    '<div class="aui-flex b-line">';
        h +=        '<div class="aui-flex-box">';
        h +=            '<h3>群名：'+data[i].name+'</h3>';
        h +=            '<p>';
        h +=            data[i].lastTime;
        h +=            '</p>';
        h +=        '</div>';
        h +=        '<div class="aui-flex-box" style="position:absolute;right:20px">';
        h +=            '<p>去交流</p>';
        h +=        '</div>';
        h +=    '</div>';
        h += '</a>';
    }
    $('#msglist').html(h);
}

/**
 * 群接收消息
 * */
function getGroupAccept(){
    var groupId = $('#groupId').val();
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        getErrMsg('没有登录！',''); return;
    }
    var data = {
        app_access:app_access,
        token:userInfo.token,
        type:userInfo.type,
        cate:userInfo.cate,
        groupId:groupId
    };
    $.ajax({
        type:'post',
        url:getDomain() + 'group/accept',
        data:data,
        success:function(res){
            //console.log(res); return;
            if (res.code!=0) {
                getErrMsg('没有新消息！','');
                console.log(res.msg); return;
            }
            var i, data = res.data, h = '';
            for (i=0;i<data.length;i++) {
                if (data[i].align=='left') {
                    h += '<div class="answer" id="answer_'+data[i].id+'">';
                    h += '<div class="heard_img left">';
                    if (data[i].head) {
                        h += '<img src="'+data[i].head+'" height="40">';
                    } else {
                        h += '<img src="../images/toux01.png" height="40">';
                    }
                    h += '</div>';
                    h += '<div class="answer_text">';
                    h += '<p>'+data[i].detail+'</p>';
                    h += '<i></i>';
                    h += '</div>';
                    h += '</div>';
                } else {
                    h += '<div class="question" id="quest_'+data[i].id+'">';
                    h += '<div class="heard_img right">';
                    if (data[i].head) {
                        h += '<img src="'+data[i].head+'" height="40">';
                    } else {
                        h += '<img src="../images/toux01.png" height="40">';
                    }
                    h += '</div>';
                    h += '<div class="question_text">';
                    h += '<p>'+data[i].detail+'</p>';
                    h += '<i></i>';
                    h += '</div>';
                    h += '</div>';
                }
            }
            $('.speak_box').append(h);
            //保存到缓存
            var talkCacheKey = 'msgGroupWin_'+groupId;
            var talkCache = cacheGet(talkCacheKey);
            //console.log(talkCache,data); return;
            var talkArr = new Array();
            if (talkCache==null || talkCache=='undefined'
                || talkCache==[]) {
                for (var i2=0;i2<data.length;i2++) {
                    talkArr[i2] = {
                        id:data[i2].id,
                        align:data[i2].align,
                        head:data[i2].head,
                        detail:data[i2].detail
                    };
                }
            } else {
                var index = talkCache.length + 1;
                for (var i3=0;i3<data.length;i3++) {
                    talkArr[index+i3] = {
                        id:data[i3].id,
                        align:data[i3].align,
                        head:data[i3].head,
                        detail:data[i3].detail
                    };
                }
            }
            cacheSet(talkCacheKey,talkArr);
            console.log('获取消息，更新缓存成功！');
        },
        error:function(){
            console.log('操作失败！'); return;
        }
    });
}

/**
 * 内部消息窗口
 * 获取本地缓存
 * */
function getGroupAcceptCache(){
    var groupId = $('#groupId').val();
    var talkCacheKey = 'msgGroupWin_'+groupId;
    var talkCache = cacheGet(talkCacheKey);
    if (talkCache==null || talkCache=='undefined' || talkCache==[]) {
        return '';
    }
    var data = talkCache;
    //console.log(talkCache); return;
    var i, h = '';
    for (i=0;i<data.length;i++) {
        if (data[i]!=null && data[i]!=''
            && data[i].align=='left') {
            h += '<div class="answer" id="answer_'+data[i].id+'">';
            h += '<div class="heard_img left">';
            if (data[i].head) {
                h += '<img src="'+data[i].head+'" height="40">';
            } else {
                h += '<img src="../images/toux01.png" height="40">';
            }
            h += '</div>';
            h += '<div class="answer_text">';
            h += '<p>'+data[i].detail+'</p>';
            h += '<i></i>';
            h += '</div>';
            h += '</div>';
        } else if (data[i]!=null && data[i]!=''
            && data[i].align=='right') {
            h += '<div class="question" id="quest_'+data[i].id+'">';
            h += '<div class="heard_img right">';
            if (data[i].head) {
                h += '<img src="'+data[i].head+'" height="40">';
            } else {
                h += '<img src="../images/toux01.png" height="40">';
            }
            h += '</div>';
            h += '<div class="question_text">';
            h += '<p>'+data[i].detail+'</p>';
            h += '<i></i>';
            h += '</div>';
            h += '</div>';
        } else {
            console.log('缓存错误！');
        }
    }
    $('.speak_box').append(h);
}

/**
 * 群发送消息
 * */
function setGroupSend(){
    var quest = $('#quest').val();
    var groupId = $('#groupId').val();
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        getErrMsg('没有登录！',''); return;
    }
    if (quest==null || quest=='' || quest=='undefined') {
        getErrMsg('没有输入消息！',''); return;
    }
    var data = {
        app_access:app_access,
        token:userInfo.token,
        type:userInfo.type,
        cate:userInfo.cate,
        groupId:groupId,
        quest:quest
    };
    var question = '';
    question += '<div class="question">';
    question += '<div class="heard_img right">';
    question += '<img src="../images/toux01.png" height="40">';
    question += '</div>';
    question += '<div class="question_text">';
    question += '<p>'+quest+'</p>';
    question += '<i></i>';
    question += '</div>';
    question += '</div>';
    $('.speak_box').append(question);
    $('.write_box input').val('');
    $('.write_box input').focus();
    $.ajax({
        type: 'post',
        url: getDomain() + 'group/send',
        data: data,
        success: function(res){
            console.log(res); return
            if (res.code!=0) {
                console.log(res.msg); return;
            }
            getGroupAccept();
            return;
        },
        error:function(){
            console.log('操作失败！'); return;
        }
    });
}

/**
 * 群友列表
 * */
function getGroupStaffs(){
    var groupId = $('#groupId').val();
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        getErrMsg('没有登录！',''); return;
    }
    var data = {
        app_access:app_access,
        token:userInfo.token,
        type:userInfo.type,
        cate:userInfo.cate,
        groupId:groupId
    };
    $.ajax({
        type:'post',
        url:getDomain() + 'group/staff',
        data:data,
        success:function(res){
            //console.log(res); return;
            var h = '';
            if (res.code!=0) {
                h += '<a href="javascript:;" class="aui-six-list-item">';
                h +=    '<div class="aui-flex b-line">';
                h +=        '<div class="aui-flex-box">';
                h +=            '<h3>测试</h3>';
                h +=        '</div>';
                h +=    '</div>';
                h += '</a>';
                $('#msglist').html(h);
                console.log(res.msg); return;
            }
            var i, data = res.data; h = '';
            for (i=0;i<data.length;i++) {
                h += '<a href="javascript:;" class="aui-six-list-item">';
                h +=    '<div class="aui-flex b-line">';
                h +=        '<div class="aui-flex-box">';
                h +=            '<h3>'+data[i].name+'</h3>';
                h +=        '</div>';
                //h +=        '<div class="aui-flex-box" style="position:absolute;right:20px">';
                //h +=            '<p>去交流</p>';
                //h +=        '</div>';
                h +=    '</div>';
                h += '</a>';
            }
            $('#msglist').html(h);
            //保存到缓存
            var talkCacheKey = 'msgGroupStaff_'+groupId;
            //cacheDel(talkCacheKey); return;
            var talkCache = cacheGet(talkCacheKey);
            var talkArr = new Array();
            if (talkCache==null || talkCache=='undefined'
                || talkCache==[]) {
                for (var i2=0;i2<data.length;i2++) {
                    talkArr[i2] = {
                        id:data[i2].id,
                        name:data[i2].name
                    };
                }
            } else {
                var index = talkCache.length + 1;
                for (var i3=0;i3<data.length;i3++) {
                    talkArr[index+i3] = {
                        id:data[i3].id,
                        name:data[i3].name
                    };
                }
            }
            //console.log(talkArr); return;
            cacheSet(talkCacheKey,talkArr);
            console.log('获取消息，更新缓存成功！');
        },
        error:function(){
            console.log('操作失败！'); return;
        }
    });
}

/**
 * 内部消息窗口
 * 获取本地缓存
 * */
function getGroupStaffCache(){
    var groupId = $('#groupId').val();
    var talkCacheKey = 'msgGroupStaff_'+groupId;
    var talkCache = cacheGet(talkCacheKey);
    if (talkCache==null || talkCache=='undefined' || talkCache==[]) {
        return '';
    }
    var data = talkCache;
    //console.log(data); return;
    var i, h = '';
    for (i=0;i<data.length;i++) {
        h += '<a href="javascript:;" class="aui-six-list-item">';
        h +=    '<div class="aui-flex b-line">';
        h +=        '<div class="aui-flex-box">';
        h +=            '<h3>'+data[i].name+'</h3>';
        h +=        '</div>';
        h +=    '</div>';
        h += '</a>';
    }
    $('#msglist').html(h);
}

/**
 * URL中，获取指定参数
 * */
function getUrlParam(paraName) {
    var url = document.location.toString();
    var arrObj = url.split("?");
    if (arrObj.length > 1) {
        var arrPara = arrObj[1].split("&");
        var arr;
        for (var i = 0; i < arrPara.length; i++) {
            arr = arrPara[i].split("=");
            if (arr != null && arr[0] == paraName) {
                return decodeURI(arr[1]);
            }
        }
        return "";
    }
    else {
        return "";
    }
}





/**
 * 地址前缀
 * */
function getDomain(){
    return '/api/msg/';
}


///**
// * -------------------------
// * 本地缓存
// * -------------------------
// * */
//
///**
// * 本地缓存，获取
// * */
//function cacheGet(key){
//    //return localStorage.getItem(key);
//    return JSON.parse(localStorage.getItem(key));
//}
//
///**
// * 本地缓存，新增
// * */
//function cacheSet(key,val){
//    //var cache = cacheGet(key);
//    //if (cache!='undefined') { getErrMsg('已存在！',''); }
//    //localStorage.setItem(key,val);
//    //为防止没有设置值获取后出现object类型 转化出错,提前进行设置空字符串
//    localStorage.setItem(key, "");
//    localStorage.setItem(key, JSON.stringify(val));
//}
//
///**
// * 本地缓存，删除
// * */
//function cacheDel(key){
//    localStorage.removeItem(key);
//}
//
///**
// * 本地缓存，删除
// * */
//function cacheClear(){
//    localStorage.clear();
//}





/**
 * 错误提示框
 * */
function getErrMsg(msg,url){
    var h = '';
    h += '<span>'+msg+'</span>';
    h += '<script>';
    h += 'setTimeout("setErrClose()",1000*3); function setErrClose(){ $("#errMsg").html("").hide(); }';
    if (url!='') {
        h += 'setTimeout("setJump()",1000*3); function setJump(){ window.location.href=\''+url+'\'; }';
    }
    h += '</script>';
    $('#errMsg').html(h).show();
}